package com.jvm.oom.test;

import cn.hutool.system.SystemUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * OomTestApplication Starter
 *
 * @author mlamp
 */
@Slf4j
@SpringBootApplication
public class OomTestApplication implements ApplicationRunner {

    public static void main(String[] args) {
        for (String arg : args) {
            System.out.println(arg);
        }
        SpringApplication.run(OomTestApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) {
        long maxMemory = Runtime.getRuntime().maxMemory();
        long totalMemory = Runtime.getRuntime().totalMemory();
        long currentPid = SystemUtil.getCurrentPID();
        log.info("the running time environment [maxMemory:{}b,{}k,{}m,{}g]", maxMemory, maxMemory / 1024, maxMemory / 1024 / 1024, maxMemory / 1024 / 1024 / 1024.0);
        log.info("the running time environment [totalMemory:{}b,{}k,{}m,{}g]]", totalMemory, totalMemory / 1024, totalMemory / 1024 / 1024, totalMemory / 1024 / 1024 / 1024.0);

        log.info("the running time environment [PID:{}]", currentPid);
        SystemUtil.dumpSystemInfo();
        System.getProperties().forEach((k, v) -> System.out.println(k + " : " + v));

    }
}
